/*
 * JHeuristics - The Java Meta-Heuritics Library
 * Copyright (C) 2004-2005, Universidade Federal de Campina Grande. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.epanetgrid.otimizacao.ag;

import java.io.Serializable;

import org.jheuristics.ga.scalers.AbstractFitnessScaler;
import org.jheuristics.ga.transformations.FitnessToDoubleTransformation;

/**
 * Vide documenta��o t�cnica para maiores detalhes.
 * Objeto utilizado no SUS para efeturar ordenamento nos cromossomos
 *
 */
public class LinearScaler extends AbstractFitnessScaler implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5611707855936485305L;

	/**
	 * 
	 * @param transformation Respons�vel por converter os fitness em um n�mero representando o conjunto
	 */
	public LinearScaler(FitnessToDoubleTransformation transformation) {
		super(transformation);
	}

	/**
	 * Vide documenta��o t�cnica para maiores detalhes.
	 * @param individuals
	 * @return
	 */
	public double[] scale(double[] fitness) {
		double[] newFitness = new double[fitness.length];

		for (int i = 0; i < newFitness.length; i++) {
	        newFitness[i] = (2.0 * i) / (newFitness.length - 1);
	    }
		for (int i = 0; i < newFitness.length; i++) {
			newFitness[i] = newFitness[i] / ((double) newFitness.length);
	    }
		return newFitness;
		
	}
	
}